package com.intel.two.controller.smarthome;

import com.intel.two.common.R;
import com.intel.two.pojo.smarthome.Guarantee;
import com.intel.two.pojo.smarthome.Household;
import com.intel.two.pojo.smarthome.Serviceman;
import com.intel.two.service.smarthome.ServicemanService;
import com.intel.two.utils.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: intelligentcommunity
 * @BelongsPackage: com.intel.two.controller.smarthome
 * @Author: yanhongwei
 * @CreateTime: 2022-10-15  14:39
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/serviceman")
public class ServicemanController {
    @Autowired
    private ServicemanService servicemanService;
    @RequestMapping("/servicemanList")
    public R servicemanList(@RequestParam Map<String, Object> parameters){
      return  servicemanService.servicemanList(parameters);
    }
//    下拉框动态回显
    @RequestMapping("/servicemanList1")
    public R servicemanList1(){
        return  servicemanService.servicemanList1();
    }
    //添加时文件上传
    @RequestMapping("/servicemanUpload")
    public R householdUpload(MultipartFile file) throws Exception {
//        文件名字
        String filename = file.getOriginalFilename();
//
        InputStream filepath = file.getInputStream();
        assert filename != null;
        String fileUrl = OssUtil.updateLoad(filepath, filename);

        return R.ok().data("fileUrl",fileUrl);
    }

//    /serviceman/servicemanAdd
//    /household/householdAdd
@RequestMapping("/servicemanAdd")
public R servicemanAdd(@RequestBody Serviceman serviceman){
    return servicemanService.servicemanAdd(serviceman);
}


    @PostMapping("/servicemanDel")
    public R  servicemanDel(@RequestBody List<Serviceman> servicemans){
        return servicemanService.servicemanDel(servicemans);
    }


}
